<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>修改参会企业</span>
        <el-button
          style="float: right; padding: 0;margin-left:14px"
          type="text"
          @click="goto('/jobfair/exhibitors/list')"
        >
          返回
        </el-button>
        <el-button
          style="float: right; padding: 0;"
          type="text"
          :disabled="issubmit"
          @click="onSubmit('form')"
        >
          保存
        </el-button>
      </div>
      <el-form
        ref="form"
        class="common-form"
        :model="form"
        label-width="120px"
        :rules="rules"
        :inline-message="true"
      >
        <el-form-item label="企业全称">
          <el-link :href="info.company_link" target="_blank" type="primary">
            {{ info.companyname }}
          </el-link>
        </el-form-item>
        <el-form-item label="预定方式" prop="etype">
          <el-radio-group v-model="form.etype">
            <el-radio :label="1">在线预定</el-radio>
            <el-radio :label="2">电话预定</el-radio>
            <el-radio :label="3">其它方式</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="预定状态" prop="audit">
          <el-radio-group v-model="form.audit">
            <el-radio :label="1">预定成功</el-radio>
            <el-radio :label="2">等待审核</el-radio>
            <el-radio :label="3">未通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          v-show="form.audit === 3"
          label="原因"
          prop="reason"
        >
          <el-input
            v-model="form.reason"
            class="middle"
            type="textarea"
            :rows="4"
            maxlength="40"
            show-word-limit
          />
        </el-form-item>
        <el-form-item label="预定招聘会">
          <el-link :href="info.jobfair_link" target="_blank" type="primary">
            {{ info.jobfair_title }}
          </el-link>
        </el-form-item>
        <el-form-item label="预定展位">
          {{ info.position }}
        </el-form-item>
        <el-form-item label="推荐名企" prop="recommend">
          <el-radio-group v-model="form.recommend">
            <el-radio :label="1">推荐</el-radio>
            <el-radio :label="0">未推荐</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="note">
          <el-input v-model="form.note" type="textarea" rows="4" />
        </el-form-item>
        <el-form-item label="">
          <el-button type="primary" :disabled="issubmit" @click="onSubmit('form')">保存</el-button>
          <el-button @click="goto('/jobfair/exhibitors/list')">返回</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { getToken } from '@/utils/auth'
import { exhibitorsEdit } from '@/api/jobfair'

export default {
  data() {
    return {
      headers: { admintoken: getToken() },
      info: {
        companyname: '',
        company_link: '',
        jobfair_title: '',
        jobfair_link: '',
        position: ''
      },
      issubmit: false,
      form: {
        id: '',
        etype: '',
        audit: '',
        recommend: '',
        note: '',
        reason: ''
      },
      rules: {
        etype: [
          { type: 'number', message: '请正确选择预定方式', trigger: 'blur' }
        ],
        audit: [
          { type: 'number', message: '请正确选择预定状态', trigger: 'blur' }
        ],
        recommend: [
          { type: 'number', message: '请正确选择推荐名企', trigger: 'blur' }
        ],
        note: [
          { max: 200, message: '长度在 200 个字符内', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getExhibitors()
  },
  methods: {
    getExhibitors: function(){
      var t = this
      this.infoLoading = true
      const param = { id: this.$route.query.id }
      exhibitorsEdit(param, 'get').then(response => {
        for (var i in t.info){
          t.info[i] = response.data.info[i]
        }
        for (var f in t.form){
          t.form[f] = response.data.info[f]
        }
        this.infoLoading = false
      }).catch(() => {})
    },
    onSubmit(formName) {
      this.issubmit = true
      const that = this
      var insertData = Object.assign({}, this.form)
      this.$refs[formName].validate(valid => {
        if (valid) {
          exhibitorsEdit(insertData).then(response => {
            this.$message.success(response.message)
            setTimeout(function() {
              that.$router.push('/jobfair/exhibitors/list')
            }, 1500)
            return true
          }).catch(() => {
            that.issubmit = false
          })
        } else {
          that.issubmit = false
          return false
        }
      })
    },
    goto(target) {
      this.$router.push(target)
    }
  }
}
</script>
<style scoped>
.map {
  height: 400px;
  max-width: 800px;
}
.thumb-uploader {
  display: inline-block;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  width: 122px;
  height: 122px;
}
.thumb-uploader img {
  width: 120px;
  height: 120px;
  border-radius: 6px;
}
.thumb-uploader:hover {
  border-color: #409eff;
}
.thumb-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 120px;
  height: 120px;
  line-height: 120px;
  text-align: center;
}
.el-textarea,
.el-select,
.el-input,
.el-date-editor {
  width: 450px;
}
</style>
